ist_demo = [1, 2, 3]
list_two = ist_demo
ist_demo[0] = 99
print(list_two)

list_demo = 'a', 'b'
de = set(list_demo)
print(de)
print(type(de))
print(type(list_demo))

dict_demo = {'a': 1, 'b': 2, 'a': 3}
print(dict_demo['a'])

print()
print('编程题')
print('1 ' * 20)


def message():
    myStr = input('请输入密码，只能是字母和数字：')
    if myStr.isalnum():
        print("符合要求")
    else:
        print('不符合要求')


message()

print('2 ' * 20)
oushu = ''
jishu = ''

lise_demo = list(input('输入任意字符：'))
for str_0 in lise_demo[::2]:
    oushu += str_0
for str_1 in lise_demo[1::2]:
    jishu += str_1
print(oushu + jishu)

print('3 ' * 20)
arr = []


def count():
    my_str = input('请输入只包含字母的字符串：')
    if my_str.isalpha():
        newstr = my_str.lower()
        for string in newstr:
            arr.append(string)

        a = {}
        for i in arr:
            if arr.count(i) >= 1:
                a[i] = arr.count(i)
        print(a)

    else:
        print('输入内容有误！！！')


count()

print('4 ' * 20)
arr = []
result = ''

my_str = input("请输入字符串：")
for string in my_str:
    arr.append(string)
last = arr[-1]
arr.pop()
arr.insert(0, last)
for new in arr:
    result += new
print(result)

print('5 ' * 20)
arr = []
length = int(input("请要输入数字的总个数（必须为奇数）:"))
i = 0
while i < length:
    num = int(input("输入第%d个数字:" % (i + 1)))
    arr.append(num)
    i += 1
arr.sort()
index = int(length - 1 >> 1)
print(arr[index])

print('6 ' * 20)
print('第一种')
arr = [1, 2, 3, 4, 5]
arr.reverse()
print(arr)
print('第二种')
arr.sort(reverse=True)
print(arr)

print('7 ' * 20)
arr = []
length = int(input("请输入数字的总个数:"))
i = 0
while i < length:
    num = int(input("输入第%d个数字:" % (i + 1)))
    arr.append(num)
    i += 1
print("排序前：%s" % arr)
# 冒泡排序
for i in range(length):
    flag = 0
    for j in range(i + 1, length):
        if arr[j - 1] > arr[j]:
            arr[j - 1], arr[j] = arr[j], arr[j - 1]
            flag = 1
    if not flag:
        break

print("排序后：%s" % arr)

print('8 ' * 20)
arr = []
length = int(input("请输入列表的总个数:"))
i = 0
while i < length:
    element = input("输入第%d个元素:" % (i + 1))
    arr.append(element)
    i += 1
# 列表转为集合
newList = set(arr)
print(newList)

print('9 ' * 20)
def add(a, b):
    # 下面两行保证输入的a和b是维数相同的矩阵，根据实际情况不要也可以
    assert (len(a) == len(b))
    assert (all([len(a[i]) == len(b[i]) == len(a[0]) for i in range(len(a))]))
    i, j = len(a), len(a[0])
    c = [[0] * j] * i
    for m in range(i):
        for n in range(j):
            c[m][n] = a[m][n] + b[m][n]
    return c


a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
b = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]
c = add(a, b)
print(c)

print("10 " * 20)
dic = {}
i=0
while i<3:
     number = input("输入学生学号：")
     name = input("输入学生姓名：")
     dic.__setitem__(number,name)
     i+=1
print("排序前：%s"%dic)
def dict2list(dic:dict):
    ''' 将字典转化为列表 '''
    keys = dic.keys()
    vals = dic.values()
    lst = [(key, val) for key, val in zip(keys, vals)]
    return lst
new = sorted(dict2list(dic), key=lambda x:x[0], reverse=False)
print("排序后：%s"%new)

print('11'*20)
def delMale(dict):
    keys = []
    values = []
    for (key,value) in dict.items():
        keys.append(key)
        values.append(value)
    for value in values:
        if value == 0:
            index = values.index(value)
            arrKey = keys[index]
            del dict[arrKey]
            values[index] = 3
            keys[index] = "占位"
dic = {"小明":0, "小红":1,"小兰":1,"小白":0}
print("删除前：%s"%dic)
delMale(dic)
print("删除后：%s"%dic)

print('12 '*20)
arr = [12,3,37,7,91,67,27,45,6]
def delPrime(arr):
    for element in arr:
        # 质数大于 1
        if element > 1:
            # 查看因子
            for i in range(2, element):
                if (element % i) == 0:
                    break
            else:
                arr.remove(element)
delPrime(arr)
print(arr)
